;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var dialog = require("dialog");
	var router = require("../hash/pageRouter");
	var databind = require("databind");
	var css_riskWarning = require("./riskWarning.css");
	var html_riskDetailInfo = require("../exception/html_riskDetailInfo.html");
	var html_settlement = require("../exception/html_settlement.html");
	var oData = {
		pageIndex: 1,
		pageSize: 10, 
		totalPageCount: 1, 
		totalRecordCount: 0
	}
	var pageIndex = 1, pageSize = 10, totalPageCount = 1, totalRecordCount = 0; // 分页初始化
	var tools = require("tools");
	var settled;
	
	var init = function(page) {
		if (page.params != null) {
			settled = page.params.settled;
		}
		
		initEvent();
		router.init();
	};
	
	var initEvent = function() {
		
		// 若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == ""|| base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		
		if (settled == null) {
			oData.settlementState = 0;
		} else {
			oData.settlementState = 1;
		}
		
		tools.loadList("inquireAbnormalRiskPageList.json", $("#riskWarningTable"), $("#riskWarningTpl"), oData, function(){
				//风险详情
				$("#riskWarningTable .riskDetail").unbind("click").click(function() {
					var abnormalRiskId = $(this).parent().parent("tr").attr("abnormalRiskId");
					inquireAbnormalRiskDetail(abnormalRiskId);
				});
				
				if (settled == true) {
					$(".riskdeal").removeClass("none");
				}
				
				//风险处理
				$(".riskdeal").unbind("click").click(function() {
					$("#popdialog").html(html_settlement);
					dialog.showDialog($("#settlement_risk_dialog"));
					$("#settlement_risk_dialog input[name=abnormalRiskId]").val($(this).parents("tr").attr("abnormalRiskId"));
					$("#settlement_risk_dialog .sure_yes").unbind("click").click(function() {
						databind.submitDom($("#settlement_risk_dialog"), function(){
							base.alert(1, "处理成功！");
							dialog.hideDialog($("#settlement_risk_dialog"));
							router.route("auditWarning/riskWarning.html");
						});
					});
				});
			});
	};
	
	//风险信息明细
	var inquireAbnormalRiskDetail = function(abnormalRiskId) {
		base.fnAjax({
			action: "inquireAbnormalRiskDetail.json",
			oData: {
				abnormalRiskId: abnormalRiskId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					$("#popdialog").html(html_riskDetailInfo);
					tools.requireInput($("#popdialog"));
					dialog.showDialog($("#create_risk_dialog"));
					inquireCommonSelectorList1(12, $("#create_risk_dialog .riskType"));
					inquireCommonSelectorList1(13, $("#create_risk_dialog .strategy"));
					inquireCommonSelectorList1(14, $("#create_risk_dialog .riskGrade"));
					databind.fillForm($("#create_risk_dialog"), data.datas[0]);
					databind.disableInput($("#create_risk_dialog"));
					$("#create_risk_dialog input[name=settlementMeasure]").removeClass("none");
					$("#create_risk_dialog input[name=settlementDetail]").removeClass("none");
					
					$("#create_risk_dialog .sure_yes").unbind("click").click(function() {
						dialog.hideDialog($("#create_risk_dialog"));
					});

					$(".claimMaterial").remove();

					$(".riskFileUuid").html('<a target="_blank" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + $("#riskFileUuid").val() + '">' + tools.inquireFile($("#riskFileUuid").val()) + '</a>');
				} else {
					base.alert(3, "信息获取失败");
				}
			}
		});
	};
	
	//常规选项
	var inquireCommonSelectorList1 = function(resonType, dom) {
		base.fnAjax({
			action: "inquireCommonSelectorList.json",
			async: false,
			oData: {
				resonType: resonType
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					//					$(dom).html("");
					$.each(data.datas, function(i, v) {
						$(dom).append('<option value=' + this.index + '>' + this.reson + '</option>');
					});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};
	
	return {
		init : init
	};
});